package course.mycollection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Predicate;

public class Demo1 {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<>();
        collection.add("aaa");
        collection.add("ccc");
        collection.add("aa");
        collection.add("acc");
        collection.add("dddd");

//        collection.removeIf(new Predicate<String>() {
//            @Override
//            public boolean test(String s) {
//                return s.length() == 3;
//            }
//        });
//
//        System.out.println(collection);
        Iterator<String> iterator = collection.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }

        while (iterator.hasNext()){
            String s = iterator.next();
            if("aa".equals(s)){
                iterator.remove();
            }
        }

        System.out.println(collection);
    }
}
